import 'package:flutter/material.dart';

class MyLoadingButton extends StatelessWidget {
  final VoidCallback onTap;
  final Widget child;
  final Color color;
  final double width;
  final double height;
  final double radius;
  final bool isLoading;
  const MyLoadingButton(
      {this.onTap,
      this.child,
      this.color,
      this.width,
      this.height,
      this.radius,
      this.isLoading});

  @override
  Widget build(BuildContext context) {
    return Material(
      borderRadius: BorderRadius.circular(radius),
      color: color,
      child: InkWell(
        onTap: onTap,
        child: Container(
          width: width,
          height: height,
          padding: const EdgeInsets.all(5.0),
          child: Center(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Offstage(
                  child: const SizedBox(
                    width: 15.0,
                    height: 15.0,
                    child: CircularProgressIndicator(
                      strokeWidth: 1.0,
                      valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
                    ),
                  ),
                  offstage: !isLoading,
                ),
                const SizedBox(
                  width: 10.0,
                ),
                child
              ],
            ),
          ),
        ),
      ),
    );
  }
}
